package fr.minuskube.inv.opener;

import com.google.common.collect.ImmutableList;
import fr.minuskube.inv.InventoryManager;
import fr.minuskube.inv.SmartInventory;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import java.util.List;

public class SpecialInventoryOpener implements InventoryOpener {
  private static final List<InventoryType> SUPPORTED = (List<InventoryType>)ImmutableList.of(InventoryType.FURNACE, InventoryType.WORKBENCH, InventoryType.DISPENSER, InventoryType.DROPPER, InventoryType.ENCHANTING, InventoryType.BREWING, InventoryType.ANVIL, InventoryType.BEACON, InventoryType.HOPPER);
  
  public Inventory open(SmartInventory inv, Player player) {
    InventoryManager manager = inv.getManager();
    Inventory handle = Bukkit.createInventory((InventoryHolder)player, inv.getType(), inv.getTitle());
    fill(handle, manager.getContents(player).get());
    player.openInventory(handle);
    return handle;
  }
  
  public boolean supports(InventoryType type) {
    return SUPPORTED.contains(type);
  }
}
